IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tr_ProjectEmails_Get]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[tr_ProjectEmails_Get]
GO

CREATE PROCEDURE [dbo].[tr_ProjectEmails_Get]
	@ProjectId UNIQUEIDENTIFIER,
	@Archived BIT = 0
AS

SELECT 
	tr_File.FileId,
	tr_File.EntryDt,
	tr_File.EmailId,
	tr_File.FileName,
	tr_File.MimeType,
	tr_File.FileLocation,
	--tr_File.FileData,
	tr_Email.Subject,
	tr_Email.EmailAddress 
FROM
	tr_Project
	INNER JOIN tr_File ON tr_Project.ProjectId = tr_File.ProjectId
	INNER JOIN tr_Email ON tr_Email.EmailId = tr_File.EmailId
WHERE
	tr_Project.ProjectId = @ProjectId 
	AND tr_File.DeletedInd = 0
	AND tr_File.ArchivedInd = @Archived








